<?php

namespace Wcent\Model;

use Think\Model;

class OcrModel extends Model
{
    protected $autoCheckFields = false;

    /**
     * 获取账户信息
     * @param type $phone
     * @return type
     */
    public function getUserinfo($phone)
    {
        $saleagent = M("saleagent");
        $salestaff = M("salestaff");
        $agent = $saleagent->where("sag_phone='" . $phone . "'")->find();
        if ($agent != null) {
            return array(
                "id" => $agent["sag_id"], "phone" => $phone,
                "name" => $agent["sag_name"],
                "type" => $agent["sag_type"]
            );
        }
        $staff = $salestaff->where("ssa_phone='" . $phone . "'")->find();
        if ($staff != null) {
            return array(
                "id" => $staff["ssa_id"], "phone" => $phone,
                "name" => $staff["ssa_name"],
                "type" => $staff["ssa_type"]
            );
        }
        return null;
    }

    /**
     * 获取销售业绩
     * @param type $phone
     * @param type $cash
     * @return type
     */
    public function getSaledata($phone, $cash)
    {
        $type = $this->getUserinfo($phone);
        if ($type["type"] != 2301 || $type["type"] != 2302) {
            return $this->getPartbill($type["id"], $cash);
        }
        $this->getAgentbill($type["id"], $cash);
    }

    /**
     * 21,13,14
     * @param type $id
     * @param type $c
     * @return type
     */
    private function getPartbill($id, $c)
    {
        $disisbn = M("disisbn");
        $code = $disisbn->where("dis_ssaid=" . $id)->find();
        if ($c == 0) {
            return $this->getCascord(array("c_disid" => $code["dis_id"]));
        }
        $where["c_disid"] = $code["dis_id"];
        $where["c_month"] = array("elt", date("Ym") - 2);
        return $this->getCascord($where);
    }

    /**
     * 2301,2302
     * @param type $id
     * @param type $c
     * @return type
     */
    private function getAgentbill($id, $c)
    {
        $cilWhere["c_agent"] = $id;
        $ageWhere["c_agent"] = $id;
        $ageWhere["c_month"] = array("elt", date("Ym") - 2);
        return $c == 0 ? $this->getCascord($cilWhere) : $this->getCascord($ageWhere);
    }

    /**
     * 获取所有成交记录
     * @param type $where

    private function getAllcord($where) {
        $couponhis = M("couponhis");
        $deallogs = M("deallogs");
        $list = $couponhis->where($where)->select();
        $tempArr = i_array_column($list, "cou_orders");
        $inStr = implode(",", $tempArr);
        if ($inStr == NULL) {
            return NULL;
        }
        $retWer["dll_ordsn"] = array("in", $inStr);
        $ret = getpages($deallogs, $retWer);
        return $ret;
    }
     */

    /**
     * 获取完成记录
     * @param type $where
     * @return type
     */
    private function getCascord($where)
    {
        $cash = M("cash");
        $ret = getpages($cash, $where);
        return $ret;
    }
}
